package org.apache.ibatis.test_clxmm.test03_cache;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.test_clxmm.test03_cache.mapper.UserMapper;
import org.apache.ibatis.test_clxmm.test03_cache.util.SqlSessionUtil;
import org.junit.jupiter.api.Test;

public class Main2Level2 {


  /**
   * SqlSession 关闭时，一级缓存的数据进入二级缓存
   * 二级缓存中有数据时，直接取出，不会预先开启 Connection （按需加载的思想）
   */

  @Test
  public void test1()  throws Exception{


    SqlSession sqlSession = SqlSessionUtil.getSqlSession();

    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

    System.out.println("1-findAll");
    userMapper.findAll();

    System.out.println("2-findAll");
    userMapper.findAll();

    sqlSession.close();


    // 开启一个新的SqlSession，测试二级缓存

    SqlSession sqlSession2 = SqlSessionUtil.getSqlSession();
    UserMapper userMapper2 = sqlSession2.getMapper(UserMapper.class);
    System.out.println("sqlSession2执行findAll......");
    userMapper2.findAll();








  }








}
